﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using System.Web.UI;
using Kevin.Shop.Business.Products.Components.Content;
using Kevin.Shop.Business.Service.Entity.Helper;
using RiderShop.Mobile.Modle;
using Kevin.Shop.Business.Core.Components;
using Kevin.Shop.Business.Products.Components;
using Kevin.Shop.Business.Service.Entity.Products.Enumerations;
using System.Collections.Specialized;
using RiderShop.Mobile.Common.Component;
using Kevin.Shop.Business.Comments.Components;
using RiderShop.Mobile.Modle.MyAccount;
using RiderShop.Mobile.Modle.Product;
using RiderShop.Mobile.ServiceEntity.Product;
using Kevin.Shop.Business.Core.Components.Responser;
using RiderShop.Mobile.Common.Component.OAuth.Weixing;
using Kevin.Shop.Business.Service.Entity.SalesManagement.Promotion;

namespace RiderShop.Mobile.Controllers
{
    public partial class ProductController : ThemeController
    {
        #region Get Special Price Product List
        /// <summary>
        /// 得到限时特价的商品
        /// </summary>
        /// <param name="pageIndex">当前页索引</param>
        /// <returns>得到限时特价的商品</returns>
        //[HttpGet]
        public ActionResult SpecialPriceProduct(int pageIndex = 0)
        {
            var model = new ProductListModel();
            var query = new GroupBuyProductQuery()
            {
                PageIndex = pageIndex,
                PageSize = 30
            };
            model.GetSpecialPriceProducts(query);

            return View(WebClientContext.Current.SiteTheme, "Product", "SpecialPriceProduct", WebClientContext.Current.CacheKeyDefaultMasterPage, model);
        }

        /// <summary>
        /// 异步得到限时特价的商品
        /// </summary>
        /// <param name="pageIndex">当前页索引</param>
        /// <returns>得到限时特价的商品</returns>
        [HttpGet]
        public JsonResult SpecialPriceProductByAjaxRequest(int pageIndex = 0)
        {
            var model = new ProductListModel();
            var query = new GroupBuyProductQuery()
            {
                PageIndex = pageIndex,
                PageSize = 30
            };
            model.GetSpecialPriceProducts(query);

            return Json(model.Result.Data, JsonRequestBehavior.AllowGet);
        }
        #endregion


        /// <summary>
        /// 提醒我
        /// </summary>
        /// <param name="productId">商品Id</param>
        /// <param name="notifyDate">通知时间</param>
        /// <returns></returns>
        [Authorize]
        public ActionResult ReminderMe(string productId, string notifyDate, string productName)
        {
            if (string.IsNullOrEmpty(productId) || string.IsNullOrEmpty(notifyDate) || string.IsNullOrEmpty(productName))
            {
                return View(WebClientContext.Current.SiteTheme, "Product", "ReminderMe", WebClientContext.Current.CacheKeyDefaultMasterPage, "商品不存在！");
            }

            ProductListModel model = new ProductListModel();
            productName = Server.UrlDecode(productName);
            
            var result = model.ReminderMe(productId, notifyDate, productName);
            if (result.Status == true && string.IsNullOrEmpty(result.ErrorMessage))
            {
                return View(WebClientContext.Current.SiteTheme, "Product", "ReminderMe", WebClientContext.Current.CacheKeyDefaultMasterPage, "设置提醒成功！");
            }
            else
            {
                return View(WebClientContext.Current.SiteTheme, "Product", "ReminderMe", WebClientContext.Current.CacheKeyDefaultMasterPage, result.ErrorMessage);
            }

        }
    }
}
